package com.cf.limit.core.frequency;

import com.cf.limit.core.LimitStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * game-server-JedisLimitStore
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/5/16 下午 02:25
 */
public class JedisLimitStore implements LimitStore {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public Long incr(String key) {
        return redisTemplate.opsForValue().increment(key, 1);
    }

    @Override
    public boolean expire(String key, Integer timeout) {
        return redisTemplate.expire(key, timeout, TimeUnit.SECONDS);
    }

}
